package com.hdaccp.xingmu.controller;

import com.hdaccp.xingmu.dao.DanyuanDao;
import com.hdaccp.xingmu.service.DanyuanService;
import com.hdaccp.xingmu.service.PoiService;
import org.apache.poi.util.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;

@Controller
@RequestMapping("/poi")
public class PoiConn {
    @Autowired
    private PoiService poiService ;
    @Autowired
    private DanyuanService danyuanService;
    @RequestMapping("/exportStu")
    public void export(HttpServletResponse response) throws Exception{
        InputStream is=poiService.getInputStream();
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("contentDisposition", "attachment;filename=AllUsers.xls");
        ServletOutputStream output = response.getOutputStream();
        IOUtils.copy(is,output);
    }

    @RequestMapping("/exprotb")
    public void exprotb(HttpServletResponse response) throws Exception{
        InputStream is=danyuanService.getInputStream();
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("contentDisposition", "attachment;filename=AllUsers.xls");
        ServletOutputStream output = response.getOutputStream();
        IOUtils.copy(is,output);
    }
}
